//
//  MyView.m
//  BesizePath
//
//  Created by lanou3g on 16/1/26.
//  Copyright © 2016年 徐强. All rights reserved.
//UIBezierPath:http://www.tuicool.com/articles/uyiEBv
//IOS用CGContextRef画各种图形(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形、贝塞尔曲线、图片):http://blog.csdn.net/rhljiayou/article/details/9919713

#import "MyView.h"

@interface MyView()

@property (nonatomic ,strong)NSMutableArray *arr;
@end

@implementation MyView
-(NSMutableArray *)arr{
    if (!_arr) {
        _arr = [NSMutableArray array];
    }
    return _arr;
}
//这个方法时view在呈现在window过程中最后出现会调用的方法
//
- (void)drawRect:(CGRect)rect{
//展示的View是这个：UIGraphicsGetCurrentContext();
    
    //创建对象
    UIBezierPath *path = [UIBezierPath bezierPath];
    //设置起点
    [path moveToPoint:CGPointMake(100, 100)];
    //添加线
    [path addLineToPoint:CGPointMake(200, 300)];
    [path addLineToPoint:CGPointMake(0, 300)];
    [path closePath];
    //绘制
    [path stroke];
    
    //画⭕️startAngle:起始位置与水平线夹角 endAngle:终止位置与水平线夹角 clockwise:顺时针／逆时针
    UIBezierPath *path1 = [UIBezierPath bezierPath];
    [path1 addArcWithCenter:CGPointMake(200, 200) radius:100 startAngle:0 endAngle:M_PI * 2  clockwise:YES];
    path1.lineWidth = 80;
    //线颜色
    [[UIColor brownColor] setStroke];
    //圆填充颜色
    [[UIColor greenColor]setFill];
    [path1 stroke];
    [self.arr addObject:path1];
    
    //贝塞尔曲线：切线经过（100，100），（200，200），控制点为（150，0）的曲线
    UIBezierPath *path2 = [UIBezierPath bezierPath];
    //设置起点
    [path2 moveToPoint:CGPointMake(100, 100)];
    //设置终点与控制点
    [path2 addQuadCurveToPoint:CGPointMake(200, 200) controlPoint:CGPointMake(150,0)];
    [path2 stroke];
    
    //二次贝塞尔曲线
    UIBezierPath *path3 = [UIBezierPath bezierPath];
    //设置起点
    [path3 moveToPoint:CGPointMake(50, 300)];
    [path3 addCurveToPoint:CGPointMake(300, 300) controlPoint1:CGPointMake(100, 200) controlPoint2:CGPointMake(250, 350)];
    [path3 stroke];
    
}

//作用：自定义控件图形
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //取出数组中的所画的路径
    UIBezierPath *path = self.arr.firstObject;
    //取出点击的点
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:self];
    if ([path containsPoint:point]) {
        NSLog(@"点击");
    }
}





@end
